;
; MSCMAC.SH Version 1.01 (C)1995,1996 HUDSON SOFT
; PSG楽譜データ作成用マクロ定義 アセンブラ用ヘッダーファイル(MSCMAC.SH)
;
	ifndef	_MSCMAC_SH_
_MSCMAC_SH_	equ	1

;--------------------------------------------------------------------
;	-- note data equate --
;--------------------------------------------------------------------

n_r	equ	$00	;休符
n_c	equ	$10	;ド
nsc	equ	$20	;ド＃
nbd	equ	$20	;レｂ
n_d	equ	$30	;レ
nsd	equ	$40	;レ＃
nbe	equ	$40	;ミｂ
n_e	equ	$50	;ミ
nse	equ	$60	;ミ＃(ファ)
nbf	equ	$50	;ファｂ(ミ)
n_f	equ	$60	;ファ
nsf	equ	$70	;ファ＃
nbg	equ	$70	;ソｂ
n_g	equ	$80	;ソ
nsg	equ	$90	;ソ＃
nba	equ	$90	;ラｂ
n_a	equ	$a0	;ラ
nsa	equ	$b0	;ラ＃)
nbb	equ	$b0	;シｂ
n_b	equ	$c0	;シ

;--------------------------------------------------------------------
;	-- music data macro --
;--------------------------------------------------------------------

tb_buf	=	0		; time base parameter

tone	macro	tcode,tleng
	if	tb_buf == 0
	if	tleng > 255 || tleng < 1
	fail '[ Music Macro Error ] -- Tone Length Data (Direct Mode) --'
	else
	db	tcode,tleng
	endif

	elseif	tleng > 16
	if	tleng*tb_buf > 255
	fail '[ Music Macro Error ] -- Tone Length Data (Auto Direct Mode) --'
	else
	db	$d0,0
	db	tcode,tleng*tb_buf
	db	$d0,tb_buf
;	msg	'[auto direct]  tone=$',tcode,' tbase=$',tb_buf,' tleng=$',tleng
	endif

	elseif	tleng < 1
	fail '[ Music Macro Error ] -- Tone Length Data (Timebase Mode) --'
	else
	db	tcode+(tleng-1)
	endif
	endm
;
nois	macro	ndata,nleng
	if	ndata > 11
	fail '[ Music Macro Error ] -- Noise Number --'

	elseif	tb_buf == 0
	if	nleng > 255 || nleng < 1
	fail '[ Music Macro Error ] -- Noise Length Data (Direct Mode) --'
	else
	db	16*(ndata+1),nleng
	endif

	elseif	nleng > 16
	if	nleng*tb_buf > 255
	fail '[ Music Macro Error ] -- Noise Length Data (Auto Direct Mode) --'
	else
	db	$d0,0
	db	16*(ndata+1),nleng*tb_buf
	db	$d0,tb_buf
	msg	'[auto direct] noise=$',ndata,' tbase=$',tb_buf,' nleng=$',nleng
	endif

	elseif	nleng < 1
	fail '[ Music Macro Error ] -- Noise Length Data (Timebase Mode) --'
	else
	db	16*(ndata+1)+(nleng-1)
	endif
	endm
;
tbase	macro	tb_data
	if	tb_data > 16
	fail '[ Music Macro Error ] -- Time Base Data --'
	else
	db	$d0,tb_data
tb_buf	=	tb_data
	endif
	endm
;
oct	macro	o_data
	if	(o_data > 7) || (o_data < 1)
	fail '[ Music Macro Error ] -- Octave Data --'
	else
	db	$d0+o_data
	endif
	endm
;
octu	macro
	db	$d8
	endm
;
octd	macro
	db	$d9
	endm
;
tai	macro
	db	$da
	endm
;
port	macro	por_val
	if	por_val > 127
	fail '[ Music Macro Error ] -- Portamento Data --'
	else
	db	$db,por_val
	endif
	endm
;
vol	macro	v_data
	if	v_data > 31
	fail '[ Music Macro Error ] -- Volume Data --'
	else
	db	$dc,v_data
	endif
	endm
;
pan	macro	p_data
	if	p_data > $ff
	fail '[ Music Macro Error ] -- Panpot Data --'
	else
	db	$dd,p_data
	endif
	endm
;
len	macro	l_data
	if	l_data > 8
	fail '[ Music Macro Error ] -- Length Data --'
	else
	db	$de,l_data
	endif
	endm
;
volr	macro	vr_data
	if	(vr_data sgt 31) || (vr_data slt -31)
	fail '[ Music Macro Error ] -- Volume Relative Data --'
	else
	db	$df,vr_data
	endif
	endm
;
nd_s	macro
	db	$e0
	endm
;
nd_c	macro
	db	$e0
	endm
;
d_c	macro
	db	$e1
	endm
;
d_s	macro
	db	$e1
	endm
;
segno	macro
	db	$e2
	endm
;
rpb	macro	lp_data
	if	lp_data > 255
	fail '[ Music Macro Error ] -- Loop Count Data --'
	else
	db	$e3,lp_data
	endif
	endm
;
rpe	macro
	db	$e4
	endm
;
wave	macro	w_data
	if	w_data > 127
	fail '[ Music Macro Error ] -- Wave Data --'
	else
	db	$e5,w_data
	endif
	endm
;
env	macro	e_data
	if	e_data > 127
	fail '[ Music Macro Error ] -- Enverope Data --'
	else
	db	$e6,e_data
	endif
	endm
;
fmn	macro	fn_data
	if	fn_data > 127
	fail '[ Music Macro Error ] -- FRQ Modeulation Number Data --'
	else
	db	$e7,fn_data
	endif
	endm
;
fmd	macro	fd_data
	if	fd_data > 255
	fail '[ Music Macro Error ] -- FRQ Modeulation Delay Data --'
	else
	db	$e8,fd_data
	endif
	endm
;
fmr	macro	fr_data
	if	fr_data > 7
	fail '[ Music Macro Error ] -- FMR Base Octave Data --'
	else
	db	$e9,fr_data
	endif
	endm
;
pen	macro	pn_data
	if	pn_data > 127
	fail '[ Music Macro Error ] -- Picth Enverope Number Data --'
	else
	db	$ea,pn_data
	endif
	endm
;
ped	macro	pd_data
	if	pd_data > 255
	fail '[ Music Macro Error ] -- Picth Enverope Delay Data --'
	else
	db	$eb,pd_data
	endif
	endm
;
dt	macro	d_data
	if	(d_data sgt 127) || (d_data slt -127)
	fail '[ Music Macro Error ] -- Detune Data --'
	else
	db	$ec,d_data
	endif
	endm
;
swp	macro	s_data
	if	(s_data sgt 127) || (s_data slt -127)
	fail '[ Music Macro Error ] -- Sweep Data --'
	else
	db	$ed,s_data
	endif
	endm
;
swpt	macro	st_data
	if	st_data > 255
	fail '[ Music Macro Error ] -- Sweep Time Data --'
	else
	db	$ee,st_data
	endif
	endm
;
jump	macro	j_adr
	db	$ef
	align	4
	dw	j_adr
	endm
;
call	macro	c_adr
	db	$f0
	align	4
	dw	c_adr
	endm
;
ret	macro
	db	$f1
	endm
;
trs	macro	t_data
	if	(t_data sgt 63) || (t_data slt -63)
	fail '[ Music Macro Error ] -- Transposition Data --'
	else
	db	$f2,t_data
	endif
	endm
;
trsr	macro	tr_data
	if	(tr_data sgt 63) || (tr_data slt -63)
	fail '[ Music Macro Error ] -- Transposition Relative Data --'
	else
	db	$f3,tr_data
	endif
	endm
;
mtrs	macro	mt_data
	if	(mt_data sgt 63) || (mt_data slt -63)
	fail '[ Music Macro Error ] -- Master Transposition Data --'
	else
	db	$f4,mt_data
	endif
	endm
;
vcng	macro	vc_data
	if	(vc_data sgt 127) || (vc_data slt -127)
	fail '[ Music Macro Error ] -- Volume Change Data --'
	else
	db	$f5,vc_data
	endif
	endm
;
panning	macro	pning_data
	if	pning_data > 18
	fail '[ Music Macro Error ] -- Panning Data --'
	else
	db	$f6,pning_data
	endif
	endm
;
panmove	macro	pmove_data
	db	$f7,pmove_data
	endm
;
mode	macro	m_data
	if	m_data > 2
	fail '[ Music Macro Error ] -- Mode Data --'
	else
	db	$f8,m_data
	endif
	endm
;
tocoda	macro	coda_adr
	db	$f9
	align	4
	dw	coda_adr
	endm
;
rpjump	macro	rpj_adr
	db	$fa
	align	4
	dw	rpj_adr
	endm
;
amn	macro	an_data
	if	an_data > 127
	fail '[ Music Macro Error ] -- AM Numbar Data --'
	else
	db	$fb,an_data
	endif
	endm
;
amoff	macro
	db	$fc
	endm
;
fdout	macro	sp_data
	if	sp_data > 127
	fail '[ Music Macro Error ] -- Fade Out Speed Data --'
	else
	db	$fe,sp_data
	endif
	endm
;
mend	macro
	db	$ff
	endm
;
strk	macro	strk_no
	if	strk_no > 127
	fail '[ Music Macro Error ] -- Sub Track Sound No. --'
	else
	db	$fd,$00,strk_no
	endif
	endm
;
mtrk	macro	mtrk_no
	if	mtrk_no > 127
	fail '[ Music Macro Error ] -- Main Track Sound No. --'
	else
	db	$fd,$01,mtrk_no
	endif
	endm
;
keyoff	macro
	db	$fd,$02
	endm
;
dtr	macro	dr_data
	if	(dr_data sgt 127) || (dr_data slt -127)
	fail '[ Music Macro Error ] -- Detune Relative Data --'
	else
	db	$fd,$03,dr_data
	endif
	endm
;
rerc	macro	rer_data
	db	$fd,$04
	align	2
	dh	rer_data
	endm
;
rerp	macro	rep_data
	if	rep_data > 127
	fail '[ Music Macro Error ] -- Release Ext.Number --'
	else
	db	$fd,$04
	align	4
	dw	$8000+rep_data
	endif
	endm
;
vola	macro	vola_data
	if	vola_data > 15
	fail '[ Music Macro Error ] -- Vola Data --'
	else
	db	$fd,$05,vola_data
	endif
	endm

;--------------------------------------------------------------------
;	-- enverope data macro --
;--------------------------------------------------------------------

evr	macro	r_rate
	align	2
	dh	$0200
	dh	r_rate
	endm
;
evre	macro	e_no
	if	e_no > 127
	fail '[ Music Macro Error ] -- Enverope Ext.Number Data --'
	else
	align	2
	dh	$0200
	dh	$8000+e_no
	endif
	endm
;
evl	macro	level
	if	level > 31
	fail '[ Music Macro Error ] -- Enverope Level Data --'
	else
	align	2
	dh	$0300
	dh	level*$400
	endif
	endm
;
evd	macro	d_time,d_rate
	if	d_time > 250
	fail '[ Music Macro Error ] -- Enverope Decay Time Data --'
	else
	align	2
	dh	d_time
	dh	d_rate
	endif
	endm
;
evw	macro	w_data
	if	w_data > $7f
	fail '[ Music Macro Error ] -- Enverope Wave Data --'
	else
	align	2
	dh	$0400+w_data
	endif
	endm
;
evp	macro	p_data
	if	p_data > 18
	fail '[ Music Macro Error ] -- Enverope Pan Data --'
	else
	align	2
	dh	$0500+p_data
	endif
	endm
;
eve	macro
	align	2
	dh	$0100
	endm

;--------------------------------------------------------------------
;	-- percussion data macro --
;--------------------------------------------------------------------

pnfq	macro	pn_data
	if	pn_data > 31
	fail '[ Music Macro Error ] -- Percussion Noise FRQ --'
	else
	db	pn_data
	endif
	endm
;
pjmp	macro	jp_adr
	db	$70
	align	4
	dw	jp_adr
	endm
;
plop	macro	lp_cnt,ret_adr
	if	lp_cnt > 255
	fail '[ Music Macro Error ] -- Percussion Loop Count Data --'
	else
	db	$80,lp_cnt
	align	4
	dw	ret_adr
	endif
	endm
;
pnop	macro
	db	$90
	endm
;
ptun	macro	ptu_data
	if	(ptu_data sgt 127) || (ptu_data slt -127)
	fail '[ Music Macro Error ] -- Percussion Tune Data --'
	else
	db	$a0,ptu_data
	endif
	endm
;
ptfq	macro	pt_data
	if	(pt_data > $fff) || (pt_data < 1)
	fail '[ Music Macro Error ] -- Percussion Frquency Data --'
	else
	db	$b0+(pt_data/256),(pt_data&$ff)
	endif
	endm
;
penv	macro	penv_data
	if	penv_data > 127
	fail '[ Music Macro Error ] -- Percussion Enverope Data --'
	else
	db	$c0,penv_data
	endif
	endm
;
ppan	macro	ppan_data
	if	ppan_data > $ff
	fail '[ Music Macro Error ] -- Percussion Panpot Data --'
	else
	db	$d0,ppan_data
	endif
	endm
;
pwav	macro	pwav_data
	if	pwav_data > 127
	fail '[ Music Macro Error ] -- Percussion Wave Data --'
	else
	db	$e0,pwav_data
	endif
	endm
;
pend	macro
	db	$f0
	endm
;
ppcm	macro	pcm
	if	(pcm < 1) || (pcm > 63)
	fail '[ Music Macro Error ] -- Percussion PCM Number --'
	else
	db	$60,pcm
	endif
	endm
;
ppng	macro	png
	if	png > 18
	fail '[ Music Macro Error ] -- Percussion Panning Data --'
	else
	db	$50,png
	endif
	endm
;
pvor	macro	pvr_data
	if	(pvr_data sgt 31) && (pvr_data slt -31)
	fail '[ Music Macro Error ] -- Percussion Volume Relative Data --'
	else
	db	$40,pvr_data
	endif
	endm
;
;--------------------------------------------------------------------
;	-- pitch enverope data equate --
;--------------------------------------------------------------------

pee	equ	$80

;--------------------------------------------------------------------
;	-- frq modeulation data equate --
;--------------------------------------------------------------------

lfoe	equ	$80

	endif	; !_MSCMAC_SH_
